package com.abc.http.example.high.token;

import java.util.Date;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import lombok.Data;

/**
 * @description: 讯飞授权码
 * @author: eshengtai
 * @create: 2022-12-12 16:41
 */
@Data
public class Token {
    /**
     * 延迟 60秒
     */
    private static final Integer DELAY_TIME = 60;
    /**
     * 授权码
     */
    private String token;
    /**
     * 过期时间 （秒）
     */
    private Integer timeExpire;

    /**
     * 创建日期：获取Token日期
     */
    private Date createTime;

    public void init() {
        this.timeExpire = timeExpire - DELAY_TIME;
        createTime = new Date();
    }

    /**
     * 计算超时时间
     * 
     * @return
     */
    public boolean timeOutBool() {
        long between = DateUtil.between(createTime, new Date(), DateUnit.SECOND);
        return between < timeExpire;
    }

}
